var mongoose=require('mongoose');
var User=mongoose.model('User',{
    name:String,
    number:Number,
    winner:Boolean
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');


User.update({name:'A'},{number:1101,winner:true},{upsert:true},(e,r)=>{
    if(e)throw e;
    console.log('Update:\n',r);

    User.update({name:'B'},{number:1201,winner:false},{upsert:true},(e,r)=>{
        if(e)throw e;
        console.log('Update:\n',r);


        User.update({name:'C'},{number:1301,winner:true},{upsert:true},(e,r)=>{
            if(e)throw e;
            console.log('Update:\n',r);

            User.update({name:'D'},{number:1401,winner:false},{upsert:true},(e,r)=>{
                if(e)throw e;
                console.log('Update:\n',r);

                User.find((e,r)=>{
                    if(e)throw e;
                    console.log('\nFind All:\n',JSON.stringify(r,null,2));

                    User.find({
                        $nor:[
                            {
                                number:{
                                    $in:[1101,1401]
                                }
                            },
                            {
                                winner:true
                            }
                        ]
                    },(e,r)=>{
                        if(e)throw e;
                        console.log('\nFind:\n',JSON.stringify(r,null,2));
                        process.exit(1);
                    });

                });


            });

        });

    });

});


/*
 * $nor:[{field:val}]
 *
 * 1.$nor多个条件使用数组表示
 * 2.数组中的每个对象表示一个查询条件，不满足所有条件中的，即可匹配
 * */
